//
//  mycar_appApp.swift
//  mycar_app
//
//  Created by Zhao Shuman on 2025/7/10.
//

import SwiftUI
import UIKit // 导入UIKit便于使用TCP相关功能

@main
struct mycar_appApp: App {
    // 应用程序设置
    @StateObject private var appSettings = AppSettings()
    
    // 连接设置
    @StateObject private var connectionSettings = ConnectionSettings()
    
    // TCP小车服务
    @StateObject private var tcpCarService = TCPCarService()
    
    init() {
        // 确保使用正确的Info.plist
        if let bundleInfo = Bundle.main.infoDictionary {
            print("使用的Info.plist: \(bundleInfo["CFBundleName"] as? String ?? "未知")")
        }
    }
    
    var body: some Scene {
        WindowGroup {
            // 使用ConnectionView作为初始视图
            ConnectionView()
                .environmentObject(connectionSettings)
                .environmentObject(appSettings)
                .environmentObject(tcpCarService)
                .onAppear {
                    // 确保TCP服务使用最新的连接设置
                    tcpCarService.updateConnectionSettings(connectionSettings)
                }
        }
    }
}
